﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using org.lab365.www;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]

public class WeatherService : System.Web.Services.WebService
{
    public WeatherService()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public List<Weather> GetWeatherbyCityName(string cityName)
    {
        WeatherWebService ws = new WeatherWebService();
        string[] info = ws.getWeatherbyCityName(cityName);
        int[] infoIndex = { 0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
        string[] res = new string[infoIndex.Length];
        for (int i = 0; i < infoIndex.Length; i++)
            res[i] = info[infoIndex[i]];
        List<Weather> weatherList = new List<Weather>();
        weatherList.Add(new Weather(res[1], res[4].Split(' ')[0], res[3], res[4].Split(' ')[1], res[5], res[6], res[7], res[8], res[9]));
        weatherList.Add(new Weather(res[1], res[11].Split(' ')[0], res[10], res[11].Split(' ')[1], res[12], res[13], res[14], "", ""));
        weatherList.Add(new Weather(res[1], res[16].Split(' ')[0], res[15], res[16].Split(' ')[1], res[17], res[18], res[19], "", ""));
        return weatherList;
    }
}